﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
namespace GSLMS.Entity
{
	/// <summary>
	/// 2.3.84    日志信息
	/// </summary>
	[DataContract(IsReference = true)]
	public partial class TB_SYS_LOG: IObjectWithChangeTracker, INotifyPropertyChanged
	{
		public TB_SYS_LOG()
		{}
		#region Model
		private long _id;
		private string _username;
		private Nullable<DateTime> _opdate;
		private string _modulecode;
		private string _opcontent;
		private string _opsign;
		private string _opsql;
		private string _opip;
		private string _hostmac;
		/// <summary>
		/// 记录ID唯一
		/// </summary>
		[DataMember]
		public long ID
		{
			get{return _id;}
			set{
				if ( _id!= value)
				{
					if (ChangeTracker.ChangeTrackingEnabled && ChangeTracker.State != ObjectState.Added)
					{
						throw new InvalidOperationException("属性“ID”是对象键的一部分，不可更改。仅当未跟踪对象或对象处于“已添加”状态时，才能对键属性进行更改。");
					}
					 _id = value;
					OnPropertyChanged("ID");
				}
			}
		}
		/// <summary>
		/// 用户名
		/// </summary>
		[DataMember]
		public string USERNAME
		{
			get{return _username;}
			set{
				if ( _username!= value)
				{
					 _username = value;
					OnPropertyChanged("USERNAME");
				}
			}
		}
		/// <summary>
		/// 操作日期
		/// </summary>
		[DataMember]
		public Nullable<DateTime> OPDATE
		{
			get{return _opdate;}
			set{
				if ( _opdate!= value)
				{
					 _opdate = value;
					OnPropertyChanged("OPDATE");
				}
			}
		}
		/// <summary>
		/// 操作模块标识符
		/// </summary>
		[DataMember]
		public string MODULECODE
		{
			get{return _modulecode;}
			set{
				if ( _modulecode!= value)
				{
					 _modulecode = value;
					OnPropertyChanged("MODULECODE");
				}
			}
		}
		/// <summary>
		/// 操作内容描述
		/// </summary>
		[DataMember]
		public string OPCONTENT
		{
			get{return _opcontent;}
			set{
				if ( _opcontent!= value)
				{
					 _opcontent = value;
					OnPropertyChanged("OPCONTENT");
				}
			}
		}
		/// <summary>
		/// 动作
		/// </summary>
		[DataMember]
		public string OPSIGN
		{
			get{return _opsign;}
			set{
				if ( _opsign!= value)
				{
					 _opsign = value;
					OnPropertyChanged("OPSIGN");
				}
			}
		}
		/// <summary>
		/// 操作SQL
		/// </summary>
		[DataMember]
		public string OPSQL
		{
			get{return _opsql;}
			set{
				if ( _opsql!= value)
				{
					 _opsql = value;
					OnPropertyChanged("OPSQL");
				}
			}
		}
		/// <summary>
		/// 操作主机IP
		/// </summary>
		[DataMember]
		public string OPIP
		{
			get{return _opip;}
			set{
				if ( _opip!= value)
				{
					 _opip = value;
					OnPropertyChanged("OPIP");
				}
			}
		}
		/// <summary>
		/// 操作主机的MAC地址
		/// </summary>
		[DataMember]
		public string HOSTMAC
		{
			get{return _hostmac;}
			set{
				if ( _hostmac!= value)
				{
					 _hostmac = value;
					OnPropertyChanged("HOSTMAC");
				}
			}
		}
		#endregion Model

	#region ChangeTracking
	   
	protected virtual void OnPropertyChanged(String propertyName)
	{
	    if (ChangeTracker.State != ObjectState.Added && ChangeTracker.State != ObjectState.Deleted)
	    {
	        ChangeTracker.State = ObjectState.Modified;
	    }
	    if (_propertyChanged != null)
	    {
	        _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
	    }
	}
	   
	protected virtual void OnNavigationPropertyChanged(String propertyName)
	{
	    if (_propertyChanged != null)
	    {
	        _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
	    }
	}
	   
	event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged{ add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
	private event PropertyChangedEventHandler _propertyChanged;
	private ObjectChangeTracker _changeTracker;
	   
	[DataMember]
	public ObjectChangeTracker ChangeTracker
	{
	    get
	    {
	        if (_changeTracker == null)
	        {
	            _changeTracker = new ObjectChangeTracker();
	            _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
	        }
	        return _changeTracker;
	    }
	    set
	    {
	        if(_changeTracker != null)
	        {
	            _changeTracker.ObjectStateChanging -= HandleObjectStateChanging;
	        }
	        _changeTracker = value;
	        if(_changeTracker != null)
	        {
	            _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
	        }
	    }
	}
	   
	private void HandleObjectStateChanging(object sender, ObjectStateChangingEventArgs e)
	{
	    if (e.NewState == ObjectState.Deleted)
	    {
	        ClearNavigationProperties();
	    }
	}
	   
	protected bool IsDeserializing { get; private set; }
	   
	[OnDeserializing]
	public void OnDeserializingMethod(StreamingContext context)
	{
	    IsDeserializing = true;
	}
	   
	[OnDeserialized]
	public void OnDeserializedMethod(StreamingContext context)
	{
	    IsDeserializing = false;
	    ChangeTracker.ChangeTrackingEnabled = true;
	}
	   
	protected virtual void ClearNavigationProperties()
	{
	}
	
	#endregion

	}
}

